const NAT = require("net");

// create once client socket
const sk = NAT.createConnection({
    host: '127.0.0.1',
    port: '1334',
}, () => {
    console.log('connection is ok')
});


sk.on('close', () => {
    console.log('server is close')
});

sk.on('end', () => {
    console.log('data is geted')
});

sk.on('error', (err) => {
    console.log(err);   
});

sk.on('data', (msg) => {
    console.log(msg);
});

sk.on('connect', () => {
    // 这里可以不用new Buffer 默认会参照utf8码表转成一个buf
    sk.write(new Buffer("ding.luchao"));
    sk.end(1); // 相当于关闭和对方的句柄
})